package com.tms.project.tms.topic.controller;

import java.util.List;

import com.tms.project.tms.record.domain.TeacherRecord;
import com.tms.project.tms.record.service.ITeacherRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.tms.framework.aspectj.lang.annotation.Log;
import com.tms.framework.aspectj.lang.enums.BusinessType;
import com.tms.project.tms.topic.domain.ScoreTopic;
import com.tms.project.tms.topic.service.IScoreTopicService;
import com.tms.framework.web.controller.BaseController;
import com.tms.framework.web.domain.AjaxResult;
import com.tms.common.utils.poi.ExcelUtil;
import com.tms.framework.web.page.TableDataInfo;

/**
 * 教师评分题库管理Controller
 *
 * @author xyl
 * @date 2021-03-24
 */
@Controller
@RequestMapping("/tms/topic")
public class ScoreTopicController extends BaseController {
    private String prefix = "tms/topic";

    @Autowired
    private IScoreTopicService scoreTopicService;
    @Autowired
    private ITeacherRecordService teacherRecordService;

    @RequiresPermissions("tms:topic:view")
    @GetMapping()
    public String topic() {
        return prefix + "/topic";
    }

    /**
     * 查询教师评分题库管理列表
     */
    @RequiresPermissions("tms:topic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScoreTopic scoreTopic) {
        startPage();
        List<ScoreTopic> list = scoreTopicService.selectScoreTopicList(scoreTopic);
        return getDataTable(list);
    }

    /**
     * 导出教师评分题库管理列表
     */
    @RequiresPermissions("tms:topic:export")
    @Log(title = "教师评分题库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScoreTopic scoreTopic) {
        List<ScoreTopic> list = scoreTopicService.selectScoreTopicList(scoreTopic);
        ExcelUtil<ScoreTopic> util = new ExcelUtil<ScoreTopic>(ScoreTopic.class);
        return util.exportExcel(list, "topic");
    }

    /**
     * 新增教师评分题库管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    /**
     * 师德师风组题, 进行答题 , 公共接口
     */
    @GetMapping("/compose/type1")
    public String questionCompose1(ModelMap mmap) {
        ScoreTopic topic = new ScoreTopic();
        topic.setScoreType(1);
        mmap.put("type",1);
        mmap.put("scoreTopic",scoreTopicService.selectScoreTopicList(topic));
        mmap.put("teacher",teacherRecordService.selectTeacherRecordList(null));
        return prefix + "/compose";
    }

    /**
     * 效绩考核组题, 进行答题
     */
    @RequiresPermissions("tms:topic:compose")
    @GetMapping("/compose/type2")
    public String questionCompose2(ModelMap mmap) {
        ScoreTopic topic = new ScoreTopic();
        topic.setScoreType(2);
        mmap.put("type",2);
        mmap.put("scoreTopic",scoreTopicService.selectScoreTopicList(topic));
        mmap.put("teacher",teacherRecordService.selectTeacherRecordList(null));
        return prefix + "/compose";
    }

    /**
     * 新增保存教师评分题库管理
     */
    @RequiresPermissions("tms:topic:add")
    @Log(title = "教师评分题库管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScoreTopic scoreTopic) {
        return toAjax(scoreTopicService.insertScoreTopic(scoreTopic));
    }

    /**
     * 修改教师评分题库管理
     */
    @GetMapping("/edit/{scoreTopicId}")
    public String edit(@PathVariable("scoreTopicId") Long scoreTopicId, ModelMap mmap) {
        ScoreTopic scoreTopic = scoreTopicService.selectScoreTopicById(scoreTopicId);
        mmap.put("scoreTopic", scoreTopic);
        return prefix + "/edit";
    }

    /**
     * 修改保存教师评分题库管理
     */
    @RequiresPermissions("tms:topic:edit")
    @Log(title = "教师评分题库管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScoreTopic scoreTopic) {
        return toAjax(scoreTopicService.updateScoreTopic(scoreTopic));
    }

    /**
     * 删除教师评分题库管理
     */
    @RequiresPermissions("tms:topic:remove")
    @Log(title = "教师评分题库管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(scoreTopicService.deleteScoreTopicByIds(ids));
    }


}
